package com.gaogzhen.datastructure.graph.maintest;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.gaogzhen.datastructure.graph.undirected.*;
import edu.princeton.cs.algs4.Graph;
import edu.princeton.cs.algs4.In;

import java.io.File;
import java.util.Arrays;
import java.util.List;

/**
 * @author: Administrator
 * @version: 1.0
 * @createTime: 2023/02/24 00:09
 */
public class VimTest {
    public static void main(String[] args) throws ClassNotFoundException {
        // testDepth();
        // testPaths();
        // testBreadth();
        // testCC();
        // testCycle();
        // testBipartite();
        // testSymbolGraph();
        // testDegreesOfSeparate();
        // System.out.println((char)11);

        List<String> strList = Arrays.asList("1111", "2222", "3333");

        Class<?> aClass1 = Class.forName("[Ljava\\.lang\\.String");
        System.out.println(aClass1);
        String[] strArr = strList.stream().toArray(String[]::new);
        Class<? extends String[]> aClass = strArr.getClass();
        System.out.println(aClass.getCanonicalName());
        System.out.println(Arrays.toString(strArr));

    }

    public static void testDegreesOfSeparate() {
        String filename = "movies.txt";
        String delimiter = "/";
        String source = "Bacon, Kevin";
        DegreesOfSeparation.degreesOfSeparation(filename, delimiter, source);
    }

    public static void testSymbolGraph() {
        SymbolGraph symbolGraph = new SymbolGraph("routes.txt", " ");
        System.out.println(symbolGraph.contains("ORD"));
        System.out.println(symbolGraph.indexOf("ORD"));
        System.out.println(symbolGraph.nameOf(3));
        System.out.println(symbolGraph.graph());
    }

    public static void testBipartite() {
        String path = System.getProperty("user.dir") + File.separator + "asserts/bipartite.txt";
        // String path = System.getProperty("user.dir") + File.separator + "asserts/maze.txt";
        In in = new In(path);
        Graph graph = new Graph(in);
        Bipartite bipartite = new Bipartite(graph);
        System.out.println("是否是二分图：" + bipartite.isBipartite());
        System.out.println("非二分图环：" + bipartite.cycle());
    }

    public static void testCycle() {
        String path = System.getProperty("user.dir") + File.separator + "asserts/maze.txt";
        In in = new In(path);
        Graph graph = new Graph(in);
        Cycle cycle = new Cycle(graph);
        System.out.println("是否有环：" + cycle.hasCycle());
        System.out.println("环路：" + cycle.cycle());
    }

    public static void testCC() {
        String path = System.getProperty("user.dir") + File.separator + "asserts/tinyG.txt";
        In in = new In(path);
        Graph graph = new Graph(in);
        CC cc = new CC(graph);
        int v = 0, w = 5;
        System.out.println("顶点 " + v + " 和顶点 " + w + "是否连通：" + cc.connected(v, w));
        System.out.println("顶点 " + w + "连通分量标记：" + cc.id(w));
        System.out.println("连通分量数量：" + cc.count());
        cc.display();
    }

    public static void testBreadth() {
        String path = System.getProperty("user.dir") + File.separator + "asserts/maze.txt";
        In in = new In(path);
        Graph graph = new Graph(in);
        int s = 0;
        List<Integer> integers = Arrays.asList(0, 2);
        BreadthFirstPaths paths = new BreadthFirstPaths(graph, integers);

        int v = 4;
        System.out.println(paths.distTo(v));
        System.out.println(paths.pathTo(v));
    }

    public static void testPaths() {
        String path = System.getProperty("user.dir") + File.separator + "asserts/maze.txt";
        In in = new In(path);
        Graph graph = new Graph(in);
        int s = 0;
        DepthFirstPaths depthFirstPaths = new DepthFirstPaths(graph, s);

        int v = 5;
        System.out.println(depthFirstPaths.hashPathTo(v));
        System.out.println(depthFirstPaths.pathTo(v));
    }

    public static void testDepth() {
        String path = System.getProperty("user.dir") + File.separator + "asserts/mediumG.txt";
        In in = new In(path);
        Graph graph = new Graph(in);
        int s = 0;
        DepthFirstSearch depthFirstSearch = new DepthFirstSearch(graph, s);

        int t = 5;
        System.out.println(depthFirstSearch.marked(t));
        System.out.println(depthFirstSearch.count());
    }
}
